using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace OnlineAnadolu
{
    public partial class KategoriEkle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string query = "Select categoryname,categoryid from categories where parentid=NULL";
                Database db = new Database();
                DataTable dt = db.select(query);

                ListBox1.DataTextField = "categoryname";
                ListBox1.DataValueField = "categoryid";
                ListBox1.DataSource = dt;
                ListBox1.DataBind();
            }
        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox2.DataBind();
            ListBox3.DataBind();
            
            string query = "Select categoryname,categoryid from categories where parentid='" + ListBox1.SelectedValue+ "'";
            Database db = new Database();
            DataTable dt = db.select(query);

            ListBox2.DataTextField = "categoryname";
            ListBox2.DataValueField = "categoryid";
            ListBox2.DataSource = dt;
            ListBox2.DataBind();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write(ListBox1.SelectedValue);
        }

        protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox3.DataBind();
            string query = "Select categoryname,categoryid from categories where parentid='" + ListBox2.SelectedValue + "'";
            Database db = new Database();
            DataTable dt = db.select(query);

            ListBox3.DataTextField = "categoryname";
            ListBox3.DataValueField = "categoryid";
            ListBox3.DataSource = dt;
            ListBox3.DataBind();
        }
    }
}
